var vue = new Vue({
    el: '#cqr',
    data: {
        username: '',
        password: ''
    },
    methods: {
        register: function () {
            if (vue.username == '') {
                alert("用户名不能为空！")
                return;
            }
            if (vue.password == '') {
                alert("密码不能为空！");
                return;
            }
            if (vue.username.length > 16) {
                alert("请输入长度小于16的的用户名!")
                return;
            }
            if (vue.password.length > 16) {
                alert("请输入长度小于16的的密码!");
                return;
            }
            var data = {
                username: vue.username,
                password: vue.password
            };
            $.ajax({
                type: "POST",
                url: "user/register",
                data: data,
                dataType: "JSON",
                success: function (message) {
                    if(message.state=='success'){
                        alert("注册成功");
                        window.location.href='login';
                    }else{
                        alert(message.message);
                    }
                },
                error: function (mes) {
                    alert("error");
                }
            });
        },
        toLogin:function () {
            window.location.href="login";
        }
    }
})